package View;

import Controller.SimulationHandler;
import UCM.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * This class is a modified JFrame
 *
 * @author Matthew
 *         Date: Oct 5, 2010
 *         Time: 8:59:53 PM
 */
public class MainMenu extends JFrame {

    //Declare Labels
    private JLabel MENUTITLELBL;
    //Declare Buttons

    private JButton runSimulationBttn;
    private JButton intersectionOptBttn;
    private JButton saveSimulationBttn;
    private JButton openSimulationBttn;
    private JButton openChatClientBttn;
    private JButton exitBttn;
    //Declare Panels
    private JPanel leftPanel;
    private JPanel rightPanel;
    //Declare Object References
    private SimulationHandler sh;

    /**
     * Frame Constructor
     *
     * @param shs = SimulationHandler
     */
    public MainMenu(SimulationHandler shs) {
        this.sh = shs;
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        leftPanel = new JPanel();
        rightPanel = new JPanel();

        MENUTITLELBL = new JLabel("Traffic Simulator");
        runSimulationBttn = new JButton("Run Simulation");
        intersectionOptBttn = new JButton("Intersection Options");
        saveSimulationBttn = new JButton("Save Simulation");
        openSimulationBttn = new JButton("Open Simulation");
        openChatClientBttn = new JButton("Start Chat");
        exitBttn = new JButton("Exit");

        rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));

        //Add panels to frame
        add(BorderLayout.WEST, leftPanel);
        add(BorderLayout.EAST, rightPanel);

        //Add widgets to panels
        rightPanel.add(runSimulationBttn);
        rightPanel.add(intersectionOptBttn);
        rightPanel.add(saveSimulationBttn);
        rightPanel.add(openSimulationBttn);
        rightPanel.add(openChatClientBttn);
        rightPanel.add(exitBttn);

        leftPanel.add(MENUTITLELBL);

        setTitle("Main Menu");

        pack();
        //Add Button Action Listeners
        exitBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCExitProgram(sh).run();
            }
        });
        intersectionOptBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCOpenSetSimulationWindow(sh).run();
            }
        });
        runSimulationBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCRunSimulation(sh).run();
            }
        });

        openChatClientBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCStartChat(sh).run();
            }
        });

        saveSimulationBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCSaveSimulationState(sh).run();
            }
        });

        openSimulationBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCOpenSimulationState(sh).run();
            }
        });
    }

    public JButton getRunSimulationBttn() {
        return runSimulationBttn;
    }

}
